//
//  NetWorkingTool.m
//  中关村在线0329
//
//  Created by dllo on 16/3/31.
//  Copyright © 2016年 刘万方. All rights reserved.
//

#import "NetWorkingTool.h"
#import "WFUserimageModel.h"
#import "WFHandleURL.h"
#import "WFProjectModel.h"
@implementation NetWorkingTool
+ (void)netWorkingWithURL:(NSString *)urlStr block:(void (^)(id))block {
    NSURL *url = [NSURL URLWithString:urlStr];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        dispatch_queue_t queue = dispatch_get_main_queue();
        dispatch_async(queue, ^{
        
            id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
            block(result);
            
        });
        
    }];
    [task resume];
}
+ (void)netWorkingWithURL:(NSString *)urlStr delegate:(id<NetWorkingToolDelegate>)delegate {
    NSURL *url = [NSURL URLWithString:urlStr];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        dispatch_queue_t queue = dispatch_get_main_queue();
        dispatch_async(queue, ^{
            
            id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
            [delegate bringValue:result];
            
        });
        
    }];
    [task resume];

}



@end
